<?php
	session_start();
	include('../includes/config.php');
	global $db, $FullUrl;
	
	$sql = "select * from constant where name = 'FullUrl'";

	$FullUrls = $db->getRow($sql);
	
	$FullUrl = $FullUrls['value_vn'];
	
	//$FullUrl = "/timkhachsan.vn";
	
include('../language/'.$_SESSION['lg'].'.php');
?>
	function CheckPayment()
	{ 
    	//var d1 = Date.parse(datepickerbegin);
        //var d2 = Date.parse(datepickerend);
        
        //var days_left = days_between(datepickerbegin, datepickerend)
    	if(IsEmpty('name'))	
		{
			alert('Vui lòng nhập tên');
			document.getElementById('name').focus();
			return false;
		}
		else if(IsEmpty('email'))	
		{
			alert('<?=EMAIL_VALIDATTION?>');
			document.getElementById('email').focus();
			return false;
		}
        else if(!IsEmail('email'))
		{
			alert('<?=INVALID_EMAIL?>');
			document.getElementById('email').focus();
			return false;
		}
        
        else if(IsEmpty('datepickerbegin'))	
		{
			alert('Chưa chọn ngày.');
			document.getElementById('datepickerbegin').focus();
			return false;
		}
        else if(IsEmpty('datepickerend'))	
		{
			alert('Chưa chọn ngày.');
			document.getElementById('datepickerend').focus();
			return false;
		}
        /*else if(days_left < 1)
        {
        	alert('Chọn ngày không phù hợp');
			document.getElementById('datepickerbegin').focus();
			return false;
        }*/
        else
        {
        	return true;
            return false;
        }
        	
      	return false;
    }
	function SaveEmail()
     {
      
      var result = true;
      if ($('#optin_info_name').val() == 'Họ tên')
      {
       alert('Xin bạn nhập họ tên!');
       result = false;
       }
      if (!IsEmail('optin_info_email'))
      {
       alert('Xin bạn nhập email!');
       result = false;
       }
      if (!result) return;
      
      $('#various2').trigger('click');
      $('#div_form').hide();
      $('#div_loading').show();
      
      $.post("<?=$FullUrl?>/ajax2.php?do=email&act=send",{
       name: $('#fields_fname').val(),
       email:  $('#fields_email').val() },
       function(data)
       {
           alert('Bạn đã đăng ký thành công');       
       }
       
       );
       return false;
    }
      
      
	function CheckAllOptIn()
	{
    	//alert('test');
		/*if(IsEmpty('name'))	
		{
			alert('<?=USERNAME_VALIDATTION?>');
			document.getElementById('name').focus();
			return false;
		}
		else if(IsEmpty('email'))	
		{
			alert('<?=EMAIL_VALIDATTION?>');
			document.getElementById('email').focus();
			return false;
		}
		else if(!IsEmail('email'))
		{
			alert('<?=INVALID_EMAIL?>');
			document.getElementById('email').focus();
			return false;
		}
        else if(!MatchValue('email', 'email2'))	
		{
			alert('<?=MATCH_EMAIL_VALIDATTION?>');
			document.getElementById('email').focus();
			return false;
		}
		else{
			OptInSubmitAction();
            return true;
           }*/
	}
    function CheckAllForgotPassword()
    {
    	if(IsEmpty('email_forgot'))	
		{
			alert('<?=EMAIL_VALIDATTION?>');
			document.getElementById('email_forgot').focus();
			return false;
		}
		else if(!IsEmail('email_forgot'))
		{
			alert('<?=INVALID_EMAIL?>');
			document.getElementById('email_forgot').focus();
			return false;
		} 
		else{
            return true;
           }
    }
    function CheckAllMemberChange()
	{    	
    	if(IsEmpty('password_old'))	
		{
			alert('<?=PASSWORD_VALIDATTION?>');
			document.getElementById('password_old').focus();
			return false;
		} 
    	else if(IsEmpty('password_new'))	
		{
			alert('<?=PASSWORD_VALIDATTION?>');
			document.getElementById('password_new').focus();
			return false;
		} 
        else if(!MatchValue('password_new', 'password2_new'))
        {
        	alert('<?=MATCH_PASSWORD_VALIDATTION?>');
			document.getElementById('password2_new').focus();
			return false;
        }  
		else{
            return true;
           }
	}
    function CheckAllMemberReg()
	{    	
    	if(IsEmpty('name_reg'))	
		{
			alert('<?=NAME_VALIDATTION?>');
			document.getElementById('name_reg').focus();
			return false;
		}
        else if(IsEmpty('email_reg'))	
		{
			alert('<?=EMAIL_VALIDATTION?>');
			document.getElementById('email_reg').focus();
			return false;
		}
		else if(!IsEmail('email_reg'))
		{
			alert('<?=INVALID_EMAIL?>');
			document.getElementById('email_reg').focus();
			return false;
		}
        else if(!MatchValue('email_reg', 'email2_reg'))	
		{
			alert('<?=MATCH_EMAIL_VALIDATTION?>');
			document.getElementById('email2_reg').focus();
			return false;
		}
        else if(IsEmpty('password_reg'))	
		{
			alert('<?=PASSWORD_VALIDATTION?>');
			document.getElementById('password_reg').focus();
			return false;
		} 
        else if(!MatchValue('password_reg', 'password2_reg'))
        {
        	alert('<?=MATCH_PASSWORD_VALIDATTION?>');
			document.getElementById('password2_reg').focus();
			return false;
        }  
		else{
            return true;
           }
	}
    function CheckAllEmailPassword()
	{    	
    	if(IsEmpty('email'))	
		{
			alert('<?=EMAIL_VALIDATTION?>');
			document.getElementById('email').focus();
			return false;
		}
		else if(!IsEmail('email'))
		{
			alert('<?=INVALID_EMAIL?>');
			document.getElementById('email').focus();
			return false;
		}
        else if(IsEmpty('password'))	
		{
			alert('<?=PASSWORD_VALIDATTION?>');
			document.getElementById('password').focus();
			return false;
		}        
		else{
            return true;
           }
	}
    
    function OptInSubmitAction()
    {
      document.frmOptin.email.value = document.getElementById('email').value;
      document.frmOptin.name.value = document.getElementById('name').value;
      document.frmOptin.submit() ;
    }
      function changesession(level)
    {
        
           
              $.post("<?=$FullUrl?>/ajax2.php?do=hotel&act=changesession",{
       star: "'" + level + "'",
       email:  $('#fields_email').val() },
       function(data)
       {
       		location.href = location.href ;
          // alert('Bạn đã đăng ký thành công');       
       }
       
       );
    	    
    }
    function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
	}


    function changesession_noreload(level)
    {
        
           
              $.post("<?=$FullUrl?>/ajax2.php?do=hotel&act=changesession",{
       star: "'" + level + "'",
       email:  $('#fields_email').val() },
       function(data)
       {
       		//location.href = location.href ;
          // alert('Bạn đã đăng ký thành công');       
       }
       
       );
    	 sleep(250);   
    }